# This is a sample Python script.
import pandas as pd
from collections import Counter


# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press ⌘F8 to toggle the breakpoint.

def read_tweet_bahceli_refugees():
    # Replace 'file_path' with the actual path to your Excel file
    df = pd.read_excel('/Users/AyseEsra/Desktop/tweets.xlsx', sheet_name='Devlet Bahceli - All')
    df_dict = pd.read_excel('/Users/AyseEsra/Desktop/Dictionaries.xlsx', sheet_name='Refugee Discources Dictionary')
    data_set = df_dict['Kelime'].tolist()
    print(data_set)
    # Replace 'data_set' with a list of words you want to check for
    #data_set = ['göç', 'göç dalgası', 'göçmen', 'sığınmak', 'sığınmacı','geçici sığınmacı', 'iltica', 'mülteci',
    #           'Suriye', 'Suriyeli', 'Arap', 'Suriye İç Savaşı', 'Suriye Savaşı', 'Suriye Krizi', 'Idlip', 'YPG', 'Soçi', IŞİD]

    word_counts = Counter()
    matching_rows = []
    # Iterate over each row in the Excel file
    for index, row in df.iterrows():
        tweet = row['text']  # Replace 'tweet' with the name of the column that contains the tweets in your Excel file
        # Check if the tweet includes any word in the data set
        for word in data_set:
            if word.lower() in tweet.lower():
                matching_rows.append(row)
                word_counts[word] += 1

                #print(f"Tweet '{tweet}' contains the word '{word}'.")
                #print(f"All columns for this row are: {row}")
                break  # If a word is found in the tweet, stop checking for other words in the data set

    if len(matching_rows) > 0:
        matching_df = pd.DataFrame(matching_rows)

        matching_df.to_excel('/Users/AyseEsra/Desktop/FilteredTweets/Refugees/Bahceli/BahceliFilteredTweets.xlsx', index=False)


    #for word, count in word_counts.items():
    #    print(f"The word '{word}' appears {count} times in the tweets.")

def read_tweet_aksener_refugees():
    # Replace 'file_path' with the actual path to your Excel file
    df = pd.read_excel('/Users/AyseEsra/Desktop/tweets.xlsx', sheet_name='Meral Aksener - Party Leader')
    df_dict = pd.read_excel('/Users/AyseEsra/Desktop/Dictionaries.xlsx', sheet_name='Refugee Discources Dictionary')
    data_set = df_dict['Kelime'].tolist()
    print(data_set)
    # Replace 'data_set' with a list of words you want to check for
    #data_set = ['göç', 'göç dalgası', 'göçmen', 'sığınmak', 'sığınmacı','geçici sığınmacı', 'iltica', 'mülteci',
    #           'Suriye', 'Suriyeli', 'Arap', 'Suriye İç Savaşı', 'Suriye Savaşı', 'Suriye Krizi', 'Idlip', 'YPG', 'Soçi', IŞİD]

    word_counts = Counter()
    matching_rows = []
    # Iterate over each row in the Excel file
    for index, row in df.iterrows():
        tweet = row['text']  # Replace 'tweet' with the name of the column that contains the tweets in your Excel file
        # Check if the tweet includes any word in the data set
        for word in data_set:
            if word.lower() in tweet.lower():
                matching_rows.append(row)
                word_counts[word] += 1

                #print(f"Tweet '{tweet}' contains the word '{word}'.")
                #print(f"All columns for this row are: {row}")
                break  # If a word is found in the tweet, stop checking for other words in the data set

    if len(matching_rows) > 0:
        matching_df = pd.DataFrame(matching_rows)

        matching_df.to_excel('/Users/AyseEsra/Desktop/FilteredTweets/Refugees/Aksener/AksenerFilteredTweets.xlsx', index=False)


    #for word, count in word_counts.items():
    #    print(f"The word '{word}' appears {count} times in the tweets.")

def read_tweet_ozdag_refugees():
    # Replace 'file_path' with the actual path to your Excel file
    df = pd.read_excel('/Users/AyseEsra/Desktop/tweets.xlsx', sheet_name='Umit Ozdag - Party Leader')
    df_dict = pd.read_excel('/Users/AyseEsra/Desktop/Dictionaries.xlsx', sheet_name='Refugee Discources Dictionary')
    data_set = df_dict['Kelime'].tolist()
    print(data_set)
    # Replace 'data_set' with a list of words you want to check for
    #data_set = ['göç', 'göç dalgası', 'göçmen', 'sığınmak', 'sığınmacı','geçici sığınmacı', 'iltica', 'mülteci',
    #           'Suriye', 'Suriyeli', 'Arap', 'Suriye İç Savaşı', 'Suriye Savaşı', 'Suriye Krizi', 'Idlip', 'YPG', 'Soçi', IŞİD]

    word_counts = Counter()
    matching_rows = []
    # Iterate over each row in the Excel file
    for index, row in df.iterrows():
        tweet = row['text']  # Replace 'tweet' with the name of the column that contains the tweets in your Excel file
        # Check if the tweet includes any word in the data set
        for word in data_set:
            if word.lower() in tweet.lower():
                matching_rows.append(row)
                word_counts[word] += 1

                #print(f"Tweet '{tweet}' contains the word '{word}'.")
                #print(f"All columns for this row are: {row}")
                break  # If a word is found in the tweet, stop checking for other words in the data set

    if len(matching_rows) > 0:
        matching_df = pd.DataFrame(matching_rows)

        matching_df.to_excel('/Users/AyseEsra/Desktop/FilteredTweets/Refugees/Ozdag/OzdagFilteredTweets.xlsx', index=False)


    #for word, count in word_counts.items():
    #    print(f"The word '{word}' appears {count} times in the tweets.")
def read_tweet_bahceli_nationalism():
    # Replace 'file_path' with the actual path to your Excel file
    df = pd.read_excel('/Users/AyseEsra/Desktop/tweets.xlsx', sheet_name='Devlet Bahceli - All')
    df_dict = pd.read_excel('/Users/AyseEsra/Desktop/Dictionaries.xlsx', sheet_name='Nationalism Dictionary')
    data_set = df_dict['Kelime'].tolist()
    print(data_set)
    # Replace 'data_set' with a list of words you want to check for
    #data_set = ['göç', 'göç dalgası', 'göçmen', 'sığınmak', 'sığınmacı','geçici sığınmacı', 'iltica', 'mülteci',
    #           'Suriye', 'Suriyeli', 'Arap', 'Suriye İç Savaşı', 'Suriye Savaşı', 'Suriye Krizi', 'Idlip', 'YPG', 'Soçi', IŞİD]

    word_counts = Counter()
    matching_rows = []
    # Iterate over each row in the Excel file
    for index, row in df.iterrows():
        tweet = row['text']  # Replace 'tweet' with the name of the column that contains the tweets in your Excel file
        # Check if the tweet includes any word in the data set
        for word in data_set:
            if word.lower() in tweet.lower():
                matching_rows.append(row)
                word_counts[word] += 1

                #print(f"Tweet '{tweet}' contains the word '{word}'.")
                #print(f"All columns for this row are: {row}")
                break  # If a word is found in the tweet, stop checking for other words in the data set

    if len(matching_rows) > 0:
        matching_df = pd.DataFrame(matching_rows)

        matching_df.to_excel('/Users/AyseEsra/Desktop/BahceliFilteredTweets_Nationalism.xlsx', index=False)


    #for word, count in word_counts.items():
    #    print(f"The word '{word}' appears {count} times in the tweets.")
def read_tweet_aksener_nationalism():
    # Replace 'file_path' with the actual path to your Excel file
    df = pd.read_excel('/Users/AyseEsra/Desktop/tweets.xlsx', sheet_name='Meral Aksener - Party Leader')
    df_dict = pd.read_excel('/Users/AyseEsra/Desktop/Dictionaries.xlsx', sheet_name='Nationalism Dictionary')
    data_set = df_dict['Kelime'].tolist()
    print(data_set)
    # Replace 'data_set' with a list of words you want to check for
    #data_set = ['göç', 'göç dalgası', 'göçmen', 'sığınmak', 'sığınmacı','geçici sığınmacı', 'iltica', 'mülteci',
    #           'Suriye', 'Suriyeli', 'Arap', 'Suriye İç Savaşı', 'Suriye Savaşı', 'Suriye Krizi', 'Idlip', 'YPG', 'Soçi', IŞİD]

    word_counts = Counter()
    matching_rows = []
    # Iterate over each row in the Excel file
    for index, row in df.iterrows():
        tweet = row['text']  # Replace 'tweet' with the name of the column that contains the tweets in your Excel file
        # Check if the tweet includes any word in the data set
        for word in data_set:
            if word.lower() in tweet.lower():
                matching_rows.append(row)
                word_counts[word] += 1

                #print(f"Tweet '{tweet}' contains the word '{word}'.")
                #print(f"All columns for this row are: {row}")
                break  # If a word is found in the tweet, stop checking for other words in the data set

    if len(matching_rows) > 0:
        matching_df = pd.DataFrame(matching_rows)

        matching_df.to_excel('/Users/AyseEsra/Desktop/AksenerFilteredTweets_Nationalism.xlsx', index=False)


    #for word, count in word_counts.items():
    #    print(f"The word '{word}' appears {count} times in the tweets.")
def read_tweet_ozdag_nationalism():
    # Replace 'file_path' with the actual path to your Excel file
    df = pd.read_excel('/Users/AyseEsra/Desktop/tweets.xlsx', sheet_name='Umit Ozdag - Party Leader')
    df_dict = pd.read_excel('/Users/AyseEsra/Desktop/Dictionaries.xlsx', sheet_name='Nationalism Dictionary')
    data_set = df_dict['Kelime'].tolist()
    print(data_set)
    # Replace 'data_set' with a list of words you want to check for
    #data_set = ['göç', 'göç dalgası', 'göçmen', 'sığınmak', 'sığınmacı','geçici sığınmacı', 'iltica', 'mülteci',
    #           'Suriye', 'Suriyeli', 'Arap', 'Suriye İç Savaşı', 'Suriye Savaşı', 'Suriye Krizi', 'Idlip', 'YPG', 'Soçi', IŞİD]

    word_counts = Counter()
    matching_rows = []
    # Iterate over each row in the Excel file
    for index, row in df.iterrows():
        tweet = row['text']  # Replace 'tweet' with the name of the column that contains the tweets in your Excel file
        # Check if the tweet includes any word in the data set
        for word in data_set:
            if word.lower() in tweet.lower():
                matching_rows.append(row)
                word_counts[word] += 1

                #print(f"Tweet '{tweet}' contains the word '{word}'.")
                #print(f"All columns for this row are: {row}")
                break  # If a word is found in the tweet, stop checking for other words in the data set

    if len(matching_rows) > 0:
        matching_df = pd.DataFrame(matching_rows)

        matching_df.to_excel('/Users/AyseEsra/Desktop/OzdagFilteredTweets_Nationalism.xlsx', index=False)


    #for word, count in word_counts.items():
    #    print(f"The word '{word}' appears {count} times in the tweets.")
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
 #   print_hi('PyCharm')
    read_tweet_bahceli_refugees()
    read_tweet_aksener_refugees()
    read_tweet_ozdag_refugees()
    # read_tweet_bahceli_nationalism()
    # read_tweet_aksener_nationalism()
    # read_tweet_ozdag_nationalism()

# See PyCharm help at https://www.jetbrains.com/help/pycharm/




